/*
* 文件：ConsoleOpen.cs
* 作者：王阳
* 时间：2019-5-20
* 描述：ConsoleOpen
*/
//#define ENABLED
#if ENABLED
using UnityEngine;

namespace UnityX
{
    internal class ConsoleDefaultOpen : MonoBehaviour
    {
        private float clickRange = 20;
        private float clickTime = 0;
        private float clickCount = 0;

        [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
        private static void AfterSceneLoad()
        {
            GameObject go = new GameObject("_ConsoleOpen_");
            go.hideFlags = HideFlags.HideInHierarchy;
            go.AddComponent<ConsoleDefaultOpen>();
            DontDestroyOnLoad(go);
        }
        private void Start()
        {
            clickRange = (Screen.dpi / 5) + 20;
        }
        private void Update()
        {
            if (UnityEngine.Input.GetKey(KeyCode.F1) && UnityEngine.Input.GetKeyDown(KeyCode.F12))
            {
                Console.isShow = !Console.isShow;
            }
            else if (UnityEngine.Input.GetMouseButtonDown(0))
            {
                if (UnityEngine.Input.mousePosition.magnitude < clickRange)
                {
                    if (Time.time - clickTime < 1f)
                    {
                        clickCount++;
                        if (clickCount >= 3)
                        {
                            clickCount = 0;
                            Console.isShow = !Console.isShow;
                        }
                    }
                    else
                    {
                        clickCount = 1;
                        clickTime = Time.time;
                    }
                }
            }
        }
    }
}
#endif